package team.zero.lemon.module.dictionary.web;

import team.zero.lemon.common.authz.annotation.AuthPassport;
import team.zero.lemon.common.authz.annotation.AuthPermission;
import team.zero.lemon.common.config.Global;
import team.zero.lemon.common.exception.CustomException;
import team.zero.lemon.common.mapper.JsonMapper;
import team.zero.lemon.common.persistence.Page;
import team.zero.lemon.common.web.BaseController;
import team.zero.lemon.module.dictionary.entity.Dictionary;
import team.zero.lemon.module.dictionary.service.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;

/**
 * Created by bolin on 2016/4/28.
 */
@Controller
@ResponseBody
@RequestMapping(value = "${commonPath}/dictionary", method = {RequestMethod.POST, RequestMethod.GET})
public class DictionaryController extends BaseController {

    @Autowired
    private DictionaryService dicService;
    @AuthPassport
    @RequestMapping("/query/all")
    public List<Dictionary> findAllDictionary() {
        return dicService.findAll();
    }
    @AuthPassport
    @RequestMapping("/query/parentId")
    public List<Dictionary> findByParentId(@RequestBody Dictionary dictionary) {
        List<Dictionary> result = dicService.findByParentId(dictionary);
        return result;
    }
    @AuthPassport
    @RequestMapping("/query/page/parentId")
//    @AuthPermission("sys:org:view")
    public Page<Dictionary> findDictionaryByParentId(@RequestBody Dictionary dictionary) {
        return dicService.findPage(dictionary);
    }
    @AuthPassport
    @RequestMapping("/query/id")
    public Dictionary findById(@RequestBody Dictionary dictionary) {
        return dicService.findById(dictionary.getId());
    }
    @AuthPassport
    @RequestMapping("/save")
    public int SaveDictionary(@RequestBody Dictionary dictionary) {
        return dicService.save(dictionary);
    }
    @AuthPassport
    @RequestMapping("/delete/ids")
    public int deleteDictionary(@RequestBody Dictionary dictionary) {
        return dicService.deleteLogicMulti(dictionary);
    }
}
